from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-13 14:09:41.160533
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 13, Oct, 2022
Time: 14:09:46
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6940
Nobs: 808.000 HQIC: -51.0161
Log likelihood: 10463.1 FPE: 5.71215e-23
AIC: -51.2169 Det(Omega_mle): 5.11354e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296688 0.052642 5.636 0.000
L1.Burgenland 0.109097 0.035408 3.081 0.002
L1.Kärnten -0.106427 0.018854 -5.645 0.000
L1.Niederösterreich 0.210133 0.074057 2.837 0.005
L1.Oberösterreich 0.100038 0.071041 1.408 0.159
L1.Salzburg 0.250944 0.037722 6.652 0.000
L1.Steiermark 0.038402 0.049389 0.778 0.437
L1.Tirol 0.106215 0.040053 2.652 0.008
L1.Vorarlberg -0.059098 0.034433 -1.716 0.086
L1.Wien 0.058555 0.063409 0.923 0.356
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064082 0.108978 0.588 0.557
L1.Burgenland -0.033634 0.073301 -0.459 0.646
L1.Kärnten 0.047825 0.039031 1.225 0.220
L1.Niederösterreich -0.172488 0.153312 -1.125 0.261
L1.Oberösterreich 0.385463 0.147068 2.621 0.009
L1.Salzburg 0.286762 0.078091 3.672 0.000
L1.Steiermark 0.106161 0.102244 1.038 0.299
L1.Tirol 0.313391 0.082916 3.780 0.000
L1.Vorarlberg 0.025318 0.071282 0.355 0.722
L1.Wien -0.016223 0.131268 -0.124 0.902
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189998 0.027024 7.031 0.000
L1.Burgenland 0.090298 0.018177 4.968 0.000
L1.Kärnten -0.008423 0.009679 -0.870 0.384
L1.Niederösterreich 0.264522 0.038018 6.958 0.000
L1.Oberösterreich 0.126409 0.036470 3.466 0.001
L1.Salzburg 0.047855 0.019365 2.471 0.013
L1.Steiermark 0.016868 0.025354 0.665 0.506
L1.Tirol 0.094271 0.020561 4.585 0.000
L1.Vorarlberg 0.059289 0.017676 3.354 0.001
L1.Wien 0.119974 0.032552 3.686 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109991 0.027693 3.972 0.000
L1.Burgenland 0.044297 0.018627 2.378 0.017
L1.Kärnten -0.016103 0.009918 -1.624 0.104
L1.Niederösterreich 0.192863 0.038959 4.950 0.000
L1.Oberösterreich 0.294177 0.037373 7.871 0.000
L1.Salzburg 0.115293 0.019844 5.810 0.000
L1.Steiermark 0.099725 0.025982 3.838 0.000
L1.Tirol 0.116331 0.021070 5.521 0.000
L1.Vorarlberg 0.070646 0.018114 3.900 0.000
L1.Wien -0.027610 0.033357 -0.828 0.408
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127847 0.050266 2.543 0.011
L1.Burgenland -0.051342 0.033810 -1.519 0.129
L1.Kärnten -0.040470 0.018003 -2.248 0.025
L1.Niederösterreich 0.169874 0.070715 2.402 0.016
L1.Oberösterreich 0.137388 0.067835 2.025 0.043
L1.Salzburg 0.285237 0.036019 7.919 0.000
L1.Steiermark 0.034444 0.047160 0.730 0.465
L1.Tirol 0.164885 0.038245 4.311 0.000
L1.Vorarlberg 0.103997 0.032879 3.163 0.002
L1.Wien 0.070317 0.060547 1.161 0.245
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060433 0.039826 1.517 0.129
L1.Burgenland 0.038745 0.026788 1.446 0.148
L1.Kärnten 0.050677 0.014264 3.553 0.000
L1.Niederösterreich 0.225707 0.056027 4.029 0.000
L1.Oberösterreich 0.282452 0.053745 5.255 0.000
L1.Salzburg 0.051657 0.028538 1.810 0.070
L1.Steiermark -0.007578 0.037365 -0.203 0.839
L1.Tirol 0.149856 0.030301 4.946 0.000
L1.Vorarlberg 0.070906 0.026050 2.722 0.006
L1.Wien 0.078079 0.047971 1.628 0.104
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178194 0.047607 3.743 0.000
L1.Burgenland -0.005784 0.032021 -0.181 0.857
L1.Kärnten -0.061185 0.017050 -3.588 0.000
L1.Niederösterreich -0.083986 0.066974 -1.254 0.210
L1.Oberösterreich 0.192314 0.064246 2.993 0.003
L1.Salzburg 0.057329 0.034114 1.681 0.093
L1.Steiermark 0.230349 0.044665 5.157 0.000
L1.Tirol 0.494205 0.036222 13.644 0.000
L1.Vorarlberg 0.049515 0.031139 1.590 0.112
L1.Wien -0.048703 0.057344 -0.849 0.396
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162042 0.054651 2.965 0.003
L1.Burgenland -0.011373 0.036760 -0.309 0.757
L1.Kärnten 0.065927 0.019573 3.368 0.001
L1.Niederösterreich 0.200279 0.076884 2.605 0.009
L1.Oberösterreich -0.061047 0.073753 -0.828 0.408
L1.Salzburg 0.216524 0.039162 5.529 0.000
L1.Steiermark 0.113449 0.051274 2.213 0.027
L1.Tirol 0.077112 0.041582 1.854 0.064
L1.Vorarlberg 0.124510 0.035747 3.483 0.000
L1.Wien 0.114631 0.065829 1.741 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354070 0.031815 11.129 0.000
L1.Burgenland 0.006101 0.021399 0.285 0.776
L1.Kärnten -0.023499 0.011394 -2.062 0.039
L1.Niederösterreich 0.223822 0.044757 5.001 0.000
L1.Oberösterreich 0.175209 0.042934 4.081 0.000
L1.Salzburg 0.047141 0.022798 2.068 0.039
L1.Steiermark -0.016837 0.029849 -0.564 0.573
L1.Tirol 0.108423 0.024206 4.479 0.000
L1.Vorarlberg 0.073532 0.020810 3.534 0.000
L1.Wien 0.053349 0.038322 1.392 0.164
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041189 0.152469 0.190166 0.157366 0.124622 0.113659 0.065563 0.226586
Kärnten 0.041189 1.000000 -0.002610 0.129686 0.041433 0.095985 0.429407 -0.053148 0.101208
Niederösterreich 0.152469 -0.002610 1.000000 0.337000 0.154519 0.300840 0.111154 0.183843 0.327683
Oberösterreich 0.190166 0.129686 0.337000 1.000000 0.232127 0.332665 0.172733 0.172552 0.263004
Salzburg 0.157366 0.041433 0.154519 0.232127 1.000000 0.145872 0.127281 0.149107 0.134221
Steiermark 0.124622 0.095985 0.300840 0.332665 0.145872 1.000000 0.153641 0.141171 0.079997
Tirol 0.113659 0.429407 0.111154 0.172733 0.127281 0.153641 1.000000 0.115193 0.154917
Vorarlberg 0.065563 -0.053148 0.183843 0.172552 0.149107 0.141171 0.115193 1.000000 0.007011
Wien 0.226586 0.101208 0.327683 0.263004 0.134221 0.079997 0.154917 0.007011 1.000000